import request from '@/utils/request';

/**
 * 分页查询事件记录
 */
export async function pageEvents(params) {
  const res = await request.get('/order/events/page', { params });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 查询事件记录列表
 */
export async function listEvents(params) {
  const res = await request.get('/order/events', { params });
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 根据id查询事件记录
 */
export async function getEvents(id) {
  const res = await request.get('/order/events/' + id);
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 添加事件记录
 */
export async function addEvents(data) {
  const res = await request.post('/order/events', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改事件记录
 */
export async function updateEvents(data) {
  const res = await request.put('/order/events', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 删除事件记录
 */
export async function removeEvents(id) {
  const res = await request.delete('/order/events/' + id);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
